package com.ruoyi.common.utils;


import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.extra.pinyin.PinyinUtil;
import com.ruoyi.common.utils.spring.SpringUtils;

/**
 * @author zhangsan
 */
public class IDGenerator {
    private static final String USERNAME_BASE = "0123456789";
    private static final String PASSWORD_SYMBOLS = "!@#_";
    private static final String PASSWORD_NUM = "0123456789";
    private static final String PASSWORD_LETTER = "abcdefghijklmnopqrstuvwxyz";

    /**
     * 生成Snowflake ID
     *
     * @return
     */
    public static Long nextSnowflakeId() {
        return SpringUtils.getBean(Snowflake.class).nextId();
    }

    /**
     * 根据手机号和姓名随机生成username
     *
     * @param phone
     * @param name
     * @return
     */
//    public static String nextUserName(String phone, String name) {
//        return PinyinUtil.getFirstLetter(name, "")  +
//                phone.substring(0, 3) +
//                phone.substring(7) +
//                '_' +
//                RandomUtil.randomString(USERNAME_BASE, 4);
//    }

    /**
     * 根据手机号和姓名随机生成username
     * zzc修改 修改课题组账号生成规则（姓名首字母+手机号）
     *
     * @param phone
     * @param name
     * @return
     */
    public static String nextUserName(String phone, String name) {
        return PinyinUtil.getFirstLetter(name, "") + phone;
    }

    /**
     * 生成随机密码
     *
     * @return
     */
    public static String nextPassword() {
        return RandomUtil.randomString(PASSWORD_LETTER, 4) +
                RandomUtil.randomString(PASSWORD_NUM, 3) +
                RandomUtil.randomString(PASSWORD_SYMBOLS, 1);
    }

    public static void main(String[] args) {
        System.out.println(nextPassword());
    }
}
